package com.xingkeduo.pojo.json;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.enums.UseStatus;
import com.xingkeduo.pojo.query.PostsPermsQuery;
import com.xingkeduo.pojo.table.PostsPermsTable;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.InputParamException;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.RegularUtil;

import java.text.DateFormat;

public class PostsPermsJson extends BaseJson {

	public static PostsPermsQuery createQueryForPostsPerms(String json) throws Throwable {
		PostsPermsQuery query = new PostsPermsQuery();
		JsonNode root = validJson(json);
		if (root == null)
			return query;
		query.setId(validId(root, YesNoEnum.YES));
		return query;
	}

	public static ObjectNode toJson(PostsPermsTable postsPermsTable) {
		ObjectNode root = MAPPER.createObjectNode();

		if (postsPermsTable != null)
		{
			root.put("id", postsPermsTable.getId());
			root.put("postsId", postsPermsTable.getPostsId());
			root.put("permsIds", postsPermsTable.getPermsIds());
		}
		return root;
	}

	public static PostsPermsTable createTableForModifyPostsPerms(String urlParam, PostsPermsTable postsPermsTable) throws Throwable {
		JsonNode root = validJson(urlParam);
		if (root == null)
			throw new InputParamException(InputParamException.Type.INVALID, "参数");
		postsPermsTable.setId(validId(root, YesNoEnum.YES));

		return postsPermsTable;
	}




}
